exports.add=[{
	_type:"controller",
	_config_details: {
		
	},
	_config: {
		name: "Helper",
		active:0,
		pages:1,
		skip_args:[],
		page_arg:"page"
	},

	/**
	 * Controller: Helper.paginator
	 *
	 * Parameters:
	 *		options - Object of:
	 *			options.active typeof Integer	- current active page, optional, if not given, this.fields.page is taken
	 *			options.pages typeof Integer	- number of pages
	 *
	 * Returns:
	 *		HTML
	 */
	paginator: function(config) {
		var ap;
		if ("active" in config) {
			ap=config.active*1;
		} else {
			ap=(this.fields.page||0)*1;
		}
		var space=this;
		var cntp=config.pages*1;
		var p=space.paginator=[];
		var sa={};
		sa[config.page_arg]=1;
		var baseurl=this.C("Helper","same_page",{skip_fields:sa,end:1})+"page=";
		function add_pages(start,end) {
			for (var i=start;i<end;i++) {
				p.push({url: baseurl+i,n:i+1,active: ap==i?1:0});
			}
		}
		if (cntp<=10) {
			add_pages(0,cntp);
		} else {
			if (ap<5) {
				add_pages(0,6);p.push({split:1});add_pages(cntp-1,cntp);
			} else if (ap>=cntp-5) {
				add_pages(0,1);p.push({split:1});add_pages(cntp-6,cntp);
			} else {
				add_pages(0,1);p.push({split:1});add_pages(ap-3,ap+4);p.push({split:1});add_pages(cntp-1,cntp);
			}
		}
		if (ap!=0) space.prev_page_url=baseurl+(ap-1);
		if (ap<cntp-1) space.next_page_url=baseurl+(ap+1);
		return this.Cview();
	},

	same_page: function(config) {
		var h={};
		//for (var i=0;i<config.same_fields.length;i++) h[config.same_fields[i]]=1;
		var sp=this.action_src;
		var first=1;
		for (var k in this.fields) {
			if (config.skip_fields && config.skip_fields[k]) continue;
			if (this.std_rewrite_fields && this.std_rewrite_fields[k]) continue;
			if (first) sp+="?"; else sp+="&";
			sp+=k;
			sp+="=";
			sp+=this.fields[k];
			first=0;
		}
		if (config.end) if (first) sp+="?"; else sp+="&";
		return sp;
	}
}];

